# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=tldr
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.4.1
pkgrel=1
pkgdesc="Command line client for a collection of simplified and community-driven man pages (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/tldr-pages/tldr-python-client'
msys2_references=(
  'anitya: 346842'
  'archlinux: tldr'
  'purl: pkg:pypi/tldr'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-colorama"
         "${MINGW_PACKAGE_PREFIX}-python-shtab"
         "${MINGW_PACKAGE_PREFIX}-python-termcolor")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx-argparse")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
options=('!strip')
source=("${url}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('016c0145f15839f20525e5dd5daf22fc5b17211c850aa99f759d251e58659438')

build() {
  cp -r "tldr-python-client-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  # man page
  make -C docs
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "python-build-${MSYSTEM}"

  python -m pytest
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE.md "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.md"

  # Generate shell completions
  local _complete='python -m tldr --print-completion'
  $_complete bash | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/tldr"
  $_complete zsh | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_tldr"
}
